package com.zhufeng.base.fallback;

import com.alibaba.fastjson.JSONObject;
import com.zhufeng.base.api.ShowUserApi;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @ClassName: UserFallbackFactory
 * @Description fegin接口回调工厂类
 * @author 月夜烛峰
 * @date 2022/8/31 16:58
 */
@Slf4j
@Component
public class
UserFallbackFactory implements FallbackFactory<ShowUserApi> {
    @Override
    public ShowUserApi create(Throwable throwable) {
        log.error("请求接口报错。。。");
        return new ShowUserApi() {
            @Override
            public JSONObject showUserById(int id) {
                log.info("调用工厂：id="+id);
                JSONObject json = new JSONObject();
                json.put("id", id);
                json.put("status", "error");
                json.put("type", "factory");
                json.put("msg", "no user found...");
                return json;
            }
        };
    }
}

